<template>
  <div>
    <div class="item-detail-show">
      <div class="item-detail-left">
        <div class="item-detail-big-img">
          <img :src="goodsInfo.goodsImg[imgIndex]" alt="">
        </div>
        <div class="item-detail-img-row">
          <div class="item-detail-img-small" v-for="(item, index) in goodsInfo.goodsImg" :key="index" @mouseover="showBigImg(index)">
            <img :src="item" alt="">
          </div>
        </div>
      </div>
      <div class="item-detail-right">
        <div class="item-detail-title">
          <p>
            <span class="item-detail-express">校园配送</span> {{goodsInfo.title}}</p>
        </div>
        <div class="item-detail-tag">
          <p>
            <span v-for="(item,index) in goodsInfo.tags" :key="index">【{{item}}】</span>
          </p>
        </div>
        <div class="item-detail-price-row">
          <div class="item-price-left">
            <div class="item-price-row">
              <p>
                <span class="item-price-title">租金</span>
                <span class="item-price">￥{{zujing.toFixed(2)}}</span>
                <span >{{'包含押金'+yajin.toFixed(2)}}</span>
              </p>
            </div>
            <div class="item-price-row">
              <p>
                <span class="item-price-title">优 惠 价</span>
                <span class="item-price-full-cut" v-for="(item,index) in goodsInfo.discount" :key="index">{{item}}</span>
              </p>
            </div>
            <div class="item-price-row">
              <p>
                <span class="item-price-title">促&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;销</span>
                <span class="item-price-full-cut" v-for="(item,index) in goodsInfo.promotion" :key="index">{{item}}</span>
              </p>
            </div>
          </div>
          <div class="item-price-right">
            <div class="item-remarks-sum">
              <p>累计评价</p>
              <p>
                <span class="item-remarks-num">{{goodsInfo.remarksNum}} 条</span>
              </p>
            </div>
          </div>
        </div>
        <!-- 选择颜色 -->
        <div class="item-select">
          <div class="item-select-title">
            <p>选择颜色</p>
          </div>
          <div class="item-select-column">
            <div class="item-select-row1">
              <div class="item-select-box"  v-for="(items, index) in setMeal" :key="index" @click="select(index, )" :class="{'item-select-box-active': index === selectBoxIndex}">
                <div class="boxxx">
                  <div class="item-select-img">
                  <img :src="items.img" alt="">
                </div>
                <div class="item-select-intro">
                  <p>{{items.intro}}</p>
                </div>
                </div>
              </div>
            </div>
          </div>
        </div>
        <!-- 尺码选择 -->
           <div class="item-select">
          <div class="item-select-title">
            <p>尺码选择</p>
          </div>
          <div class="item-select-column">
            <div class="item-select-row1">
              <div class="item-select-box1"  v-for="(items, index) in goodsInfo.goodsize" :key="index" @click="select1(index )" :class="{'item-select-box-active': index === sizeIndex}">
                <div class="boxxx">
                 <!--  <div class="item-select-img">
                  <img :src="items.img" alt="">
                </div> -->
                <div class="item-select-intro">
                  <p>{{items}}</p>
                </div>
                </div>
              </div>
              <!-- 尺码组手 -->
                <Poptip
              title="尺码组手">
             <Button>尺码组手</Button>
              <div class="api" slot="content">
                   <Form ref="formCustom" :model="formCustom" :rules="ruleInline" :label-width="80">
        <FormItem label="身高(cm)" prop="height">
            <Input type="number" v-model="formCustom.height"></Input>
        </FormItem>
        <FormItem label="体重(kg)" prop="weight">
            <Input type="number" v-model="formCustom.weight"></Input>
        </FormItem>
        <FormItem label="尺码组手推荐:" >
            <span v-show="issize">{{tuijian}}码</span>
           </FormItem>
        <FormItem>
            <Button type="success" @click="handleSubmit('formCustom')">确定</Button>
            <Button @click="handleReset('formCustom')" style="margin-left: 8px">重置</Button>
        </FormItem>
    </Form>
              </div>
             </Poptip>
            </div>
            </div>
        </div>
        <!-- 白条分期 -->
      <!--   <div class="item-select">
          <div class="item-select-title">
            <p>白条分期</p>
          </div>
          <div class="item-select-row">
            <div class="item-select-class" v-for="(item,index) in hirePurchase" :key="index" :class="index==flag?'active':''" @click="flag=index">
              <Tooltip :content="item.tooltip"  placement="top-start">
                <span >{{item.type}}</span>
              </Tooltip>
            </div>
          </div>
        </div> -->
        <div class="item-select">
          <div class="item-select-title">
            <p>租赁天数</p>
          </div>
          <div class="item-select-row">
            <div class="item-select-class" v-for="(item,index) in jianshu" :key="index" :class="item.value==flag1?'active':''" @click="flag1=item.value" >
              <span style="padding: 0 8px" >{{item.lable}}</span>
            </div>
             <div class="item-select-class"  :class="flag1== -1 ?'active':''" @click="flag1=-1" >
              <span style="padding: 0 16px" >自定义天数</span>
                 <Input v-model="zdyjs"  type="number" placeholder="请输入租赁天数" style="width: 150px" size="small" />
            </div>
          </div>
        </div>
        <br>
         <div class="item-select">
          <div class="item-select-title">
            <p>租赁件数</p>
          </div>
          <div class="item-select-row">
            <div class="item-select-class1" >
             <InputNumber :min="1" v-model="count" size="large"></InputNumber>
            <Button style="margin-left:30px" type="error" size="large" @click="addShoppingCartBtn()">加入购物车</Button>
            </div>
          </div>
        </div>
        <!--  <div class="item-select">
          <div class="item-select-title">
            <p>租赁费用</p>
          </div>
          <div class="item-select-row" v-show="yajin !=zujing">
            <div class="feiyong" >
              押金：{{yajin}}
            </div>
              <div class="feiyong" >
              租金：{{zujing}}
            </div>
          </div>
        </div> -->
       <!--  <div class="add-buy-car-box">
          <div class="add-buy-car">
            <InputNumber :min="1" v-model="count" size="large"></InputNumber>
            <Button type="error" size="large" @click="addShoppingCartBtn()">加入购物车</Button>
          </div>
        </div> -->
      </div>
    </div>
  </div>
</template>

<script>
import store from '@/vuex/store';
import { mapState, mapActions } from 'vuex';
export default {
  name: 'ShowGoods',
  data () {
    return {
      price: 0,
      count: 1,
      selectBoxIndex: 0,
      imgIndex: 0,
      flag: 0,
      flag1: 1,
      sizeIndex: 0,
      formCustom: {
        height: 0,
        weight: 0
      },
      ruleInline: {
        height: [
          { required: true, message: '请输入身高', trigger: 'blur' }
        ],
        weight: [
          { required: true, message: '请输入体重', trigger: 'blur' }
        ]
      },
      issize: false,
      tuijian: '',
      sizecomheight: [
        ['S', 'M'],
        ['S', 'M', 'L'],
        ['M', 'L', 'XL'],
        ['L', 'XL']
      ],
      jianshu: [
        {
          lable: '一天',
          value: 1
        },
        {
          lable: '两天',
          value: 2
        },
        {
          lable: '三天',
          value: 3
        },
        {
          lable: '四天',
          value: 4
        }
      ],
      num: 10,
      zdyjs: null,
      num1: 0,
      kc: 0
    };
  },
  computed: {
    ...mapState(['goodsInfo', 'setMeal']),
    hirePurchase () {
      const three = this.zujing * this.count / 3;
      const sex = this.zujing * this.count / 6;
      const twelve = this.zujing * this.count / 12 * 1.0025;
      const twentyFour = this.zujing * this.count / 24 * 1.005;
      return [
        {
          tooltip: '无手续费',
          type: '不分期'
        },
        {
          tooltip: '无手续费',
          type: `￥${three.toFixed(2)} x 3期`
        },
        {
          tooltip: '无手续费',
          type: `￥${sex.toFixed(2)} x 6期`
        },
        {
          tooltip: '含手续费：费率0.25%起，￥0.1起×12期',
          type: `￥${twelve.toFixed(2)} x 12期`
        },
        {
          tooltip: '含手续费：费率0.5%起，￥0.1起×12期',
          type: `￥${twentyFour.toFixed(2)} x 24期`
        }
      ];
    },
    yajin () {
      if (this.count < 10) {
        return this.count * 30;
      } else if (this.count >= 10 && this.count < 30) {
        return this.count * 25;
      } else {
        return this.count * 20;
      }
    },
    zujing () {
      let num1 = 0;
      if (this.flag1 === -1) {
        num1 = this.zdyjs;
      } else {
        num1 = this.flag1;
      }
      if (num1 < 10) {
        return num1 * 20 + this.yajin;
      } else if (num1 >= 10 && num1 < 30) {
        return num1 * 15 + this.yajin;
      } else {
        return num1 * 10 + this.yajin;
      }
    }
  },
  methods: {
    ...mapActions(['addShoppingCart', 'changekc']),
    select (index1) {
      this.selectBoxIndex = index1;
      // this.kc = this.goodsInfo.setMeal[index1].kc;
    },
    select1 (index1) {
      this.sizeIndex = index1;
    },
    showBigImg (index) {
      this.imgIndex = index;
    },
    addShoppingCartBtn () {
      const index1 = this.selectBoxIndex;
      const date = new Date();
      const goodsId = date.getTime();
      let num = 0;
      if (this.flag1 === -1) {
        num = this.zdyjs;
      } else {
        num = this.flag1;
      }
      this.changekc({index: index1, count: this.count});
      const data = {
        goods_id: goodsId,
        title: this.goodsInfo.title,
        count: this.count,
        package: this.setMeal[index1],
        size: this.goodsInfo.goodsize[this.sizeIndex],
        yajin: this.yajin,
        zujing: this.zujing,
        day: num
      };
      this.addShoppingCart(data);
      this.$router.push('/shoppingCart');
    },
    handleSubmit (name) {
      if (this.formCustom.height < 100 || this.formCustom.weight < 30) {
        this.$Message.error('请输入正确的身高体重');
        return;
      }
      let index = 0;
      if (this.formCustom.height < 170) {
        index = 0;
        if (this.formCustom.weight < 60) {
          this.tuijian = this.sizecomheight[index][0];
          this.issize = true;
        } else {
          this.tuijian = this.sizecomheight[index][1];
          this.issize = true;
        }
      } else if (this.formCustom.height >= 170 && this.formCustom.height < 178) {
        index = 1;
        if (this.formCustom.weight < 60) {
          this.tuijian = this.sizecomheight[index][0];
          this.issize = true;
        } else if (this.formCustom.weight >= 60 && this.formCustom.weight < 70) {
          this.tuijian = this.sizecomheight[index][1];
          this.issize = true;
        } else {
          this.tuijian = this.sizecomheight[index][2];
          this.issize = true;
        }
      } else if (this.formCustom.height >= 178 && this.formCustom.height < 190) {
        index = 2;
        if (this.formCustom.weight < 67.5) {
          this.tuijian = this.sizecomheight[index][0];
          this.issize = true;
        } else if (this.formCustom.weight >= 67.5 && this.formCustom.weight < 90) {
          this.tuijian = this.sizecomheight[index][1];
          this.issize = true;
        } else {
          this.tuijian = this.sizecomheight[index][2];
          this.issize = true;
        }
      } else {
        index = 3;
        if (this.formCustom.weight < 90) {
          this.tuijian = this.sizecomheight[index][0];
          this.issize = true;
        } else {
          this.tuijian = this.sizecomheight[index][1];
          this.issize = true;
        }
      }
    },
    handleReset () {
      this.formCustom.height = 0;
      this.formCustom.weight = 0;
      this.issize = false;
    }
  },
  mounted () {
  },
  store
};
</script>

<style scoped>
/******************商品图片及购买详情开始******************/
.item-detail-show {
  width: 80%;
  margin: 15px auto;
  display: flex;
  flex-direction: row;
  background-color: #fff;
}
.item-detail-left {
  width: 350px;
  margin-right: 30px;
}
.item-detail-big-img {
  width: 350px;
  height: 400px;
  box-shadow: 0px 0px 8px #ccc;
  cursor: pointer;
}
.item-detail-big-img img {
  width: 100%;
  height: 400px;
}
.item-detail-img-row {
  margin-top: 35px;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
}
.item-detail-img-small {
  width: 68px;
  height: 68px;
  box-shadow: 0px 0px 8px #ccc;
  cursor: pointer;
}
.item-detail-img-small img {
   width: 68px;
  height: 68px;
}
/*商品选购详情*/
.item-detail-right {
  display: flex;
  flex-direction: column;
}
.item-detail-title p {
  color: #666;
  font-size: 20px;
}
.item-detail-express {
  font-size: 14px;
  padding: 2px 3px;
  border-radius: 3px;
  background-color: #e4393c;
  color: #fff;
}
/*商品标签*/
.item-detail-tag {
  font-size: 12px;
  color: #e4393c;
}
/*价格详情等*/
.item-detail-price-row {
  padding: 5px;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  background-color: #f3f3f3;
}
.item-price-left {
  display: flex;
  flex-direction: column;
}
.item-price-title {
  color: #999999;
  font-size: 14px;
  margin-right: 15px;
}
.item-price-row {
  margin: 5px 0px;
}
.item-price {
  color: #e4393c;
  font-size: 23px;
  cursor: pointer;
}
.item-price-full-cut {
  margin-right: 5px;
  padding: 3px;
  color: #e4393c;
  font-size: 12px;
  background-color: #ffdedf;
  border: 1px dotted #e4393c;
  cursor: pointer;
}
.item-remarks-sum {
  padding-left: 8px;
  border-left: 1px solid #ccc;
}
.item-remarks-sum p {
  color: #999999;
  font-size: 12px;
  line-height: 10px;
  text-align: center;
}
.item-remarks-num {
  line-height: 18px;
  color: #005eb7;
}
.item-select {
  display: flex;
  flex-direction: row;
  margin-top: 15px;
}
.item-select-title {
  color: #999999;
  font-size: 14px;
  margin-right: 15px;
}
.item-select-column {
  display: flex;
  flex-direction: column;
}
.item-select-row {
  display: flex;
  flex-direction: row;
  margin-bottom: 8px;
}
.item-select-row1 {
  width:600px;
  margin-bottom: 8px;
}
.item-select-box  img{

  vertical-align: middle;
}
.item-select-img {
  width: 36px;
   display:inline-block;
}
.item-select-box {
  display:inline-block;
  /* align-items:center; */
  padding: 5px;
  width: 180px;
  margin-right: 8px;
  margin-bottom: 8px;
  background-color: #f7f7f7;
  border: 0.5px solid #ccc;
  cursor: pointer;
}
.item-select-box1 {
  display:inline-block;
  /* align-items:center; */
  padding: 5px;
  width: 80px;
  margin-right: 8px;
  margin-bottom: 8px;
  background-color: #f7f7f7;
  border: 0.5px solid #ccc;
  cursor: pointer;
}
.feiyong{
  font-size:20px
}
.boxxx{
  display:flex;
  align-items:center;
}
.item-select-box:hover {
  border: 0.5px solid #e3393c;
}
.item-select-box-active {
  border: 0.5px solid #e3393c;
}
.item-select-img img {
  width: 100%;
}
.item-select-intro p {
  display:inline-block;
  margin: 0px;
  padding: 5px;
}
.item-select-class {
  padding: 5px;
  margin-right: 8px;
  background-color: #f7f7f7;
  border: 0.5px solid #ccc;
  cursor: pointer;
}
.item-select-class:hover {
  border: 0.5px solid #e3393c;
}
.item-select-class.active{
     border: 0.5px solid #e3393c;
}
.add-buy-car-box {
  width: 100%;
  margin-top: 15px;
  border-top: 1px dotted #ccc;
}
.add-buy-car {
  margin-top: 15px;
}
/******************商品图片及购买详情结束******************/
</style>
